package org.lee.springcloud.consumer.dashboard;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

/**
 * @author jackielee
 * @version 1.0
 * @description ConsumerApplication
 * @date 2021/3/10
 **/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
public class DashboardConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(DashboardConsumerApplication.class, args);
    }

    /**
     * 添加 /hystrix.stream 访问路径
     * 在/hystrix页面下输入 http://xxx:port/actuator/hystrix.stream 点击monitor stream即可看到情况
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet hystrix = new HystrixMetricsStreamServlet();
        ServletRegistrationBean bean = new ServletRegistrationBean(hystrix);
        bean.setLoadOnStartup(1);
        bean.addUrlMappings("/actuator/hystrix.stream");
        bean.setName("HystrixMetricsStreamServlet");
        return bean;
    }
}
